<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Asset Manager
 *
 * Software to automatically manage how assets are delivered on a website
 *
 * @package		Asset Manager
 * @author		Adam Lewis <adam.lewis@bestservedcold.com>
 * @copyright	Copyright (c) 2006 - 2012, Best Served Cold Media Limited.
 * @license		http://bestservedcold.com/license.html
 * @link		http://bestservedcold.com
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * CodeIgniter Email Class
 *
 * Permits email to be sent using Mail, Sendmail, or SMTP.
 *
 * @package		Asset Manager
 * @subpackage	CDNs
 * @category	Libraries
 * @author		ExpressionEngine Dev Team
 */
class Am_cdn {

	protected $CI;

	public function __construct()
	{
		log_message('debug', '[CDN] Class initialized');
		$this->CI =& get_instance();
		$this->CI->load->config('asset_manager', TRUE);
	}

	public function put_asset($asset)
	{
		if ($this->put_file($asset['file'], $asset['filetype']))
		{
			$asset['cdn'] = $asset['file'];
			return $asset;
		}
		else
		{
			return FALSE;
		}
	}

	/**
	 * Check Asset
	 *
	 * Enter description here ...
	 *
	 * @access	private
	 * @since	2012-05-29
	 * @param	object		$asset
	 * @return	string
	 */
	protected function check_asset($asset)
	{
		$cdn = get_cdn_url($asset['cdn']);
		if (! fopen($cdn,'r'))
		{
			log_message('warning', "[ASSETS] Asset does not exist in the CDN [$cdn]");
			return FALSE;
		}
		return $cdn;
	}
}